﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microhard.FMCG.Buz.Models;
using Microhard.FMCG.Buz.Interfaces;
using HtmlAgilityPack;
using Microhard.Core.Extensions;

namespace Microhard.FMCG.Buz.Impls.KASystem.WUMart
{
    public class NewsParser : IHtmlParser<List<NewsModel>>
    {
        public List<NewsModel> ParseObject(string html)
        {
            if (string.IsNullOrEmpty(html))
                return new List<NewsModel>(); ;
            HtmlDocument doc = new HtmlDocument();
            doc.LoadHtml(html);
            //获得新闻标题
            return (from a in doc.DocumentNode.Descendants("a")
                    where a.Attributes["href"].Value.Contains("InfoPublish/Detail.aspx")
                    select new NewsModel
                    {
                        Title = a.InnerText.ToLowerAndTrim(),
                        DetailLink = a.Attributes["href"].Value
                    }).ToList();


        }
    }
}
